
import aima.search.framework.HeuristicFunction;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Marc
 */
public class CarsHeuristicFunction2 implements HeuristicFunction{

    public int getHeuristicValue(Object state) {
        State CarsState= (State)state;
        double sum = 0;
        double extraDistance = 0;
        int n = CarsState.getNDrivers();
        for (int i = 0; i < n; ++i){
            int distanceCar = CarsState.getDistanceDriver(i);
            if (distanceCar > 300) extraDistance += distanceCar - 300;
            sum += distanceCar;
        }
        sum += 1000*extraDistance;
        double NDrivers = (double)CarsState.getN()-(double)CarsState.getM();
        double fsum = 0;
        double total = 0;
        if (extraDistance == 0){
            fsum = ((sum*100) / (NDrivers*300));
            total = (((double)CarsState.getNDrivers()*100) / (NDrivers));
            sum = total + fsum;
        }
         System.out.println(" => conductors " + CarsState.getNDrivers() + " total " +NDrivers +
                " %conductors " + total + " %distancia " + fsum + " distancia extra: " + extraDistance + "  |fh: "
                + (int)sum);
        //System.out.println(" => Heur " + sum);
        return (int) sum;
    }

}
